package com.movecar.ui;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.movecar.R;
import com.movecar.listview.WaterFallListView;
import com.movecar.listview.WaterFallListView.IXListViewListener;
import com.movecar.model.GroupBean;
import com.movecar.utils.Alert;
import com.movecar.utils.AppConfig;
import com.movecar.utils.DataStore;
import com.movecar.utils.HttpPostRequestAsyncTask;
import com.movecar.utils.RequestResultCallback;
import com.movecar.utils.imageloader.Constants;
import com.movecar.widget.CustomProgressDialog;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 活动列表
 * 
 * @author Zhao.JQ
 * 
 */
public class GroupActivity extends Activity implements OnClickListener, RequestResultCallback, IXListViewListener {

	protected WaterFallListView mXList;
	// private ListView mListView;
	private List<GroupBean> mDataList;
	private List<GroupBean> resultList = new ArrayList<GroupBean>();
	private List<GroupBean> totalList = new ArrayList<GroupBean>();
	private CustomProgressDialog progressDialog = null;
	private DataAdapter dataAdapter;
	private String pageNo = "0";
	private boolean flgMore = false;
	private boolean isJoined = false;
	private boolean init = false;
	private boolean comeFromPush = false;
	private String newMessageId;
	private String sectionId, userId, ThemeId;
	private Button btn_hd, btn_ty;
	private Button btn_classification;
	private String bc;

	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.group);
		dataAdapter = new DataAdapter(GroupActivity.this);
		init = true;
		comeFromPush = getIntent().getBooleanExtra("push", false);
		if (comeFromPush) {
			newMessageId = getIntent().getStringExtra("newMessageId");
		}

		initView();
	}

	private void initView() {
		// 活动列表
		mXList = (WaterFallListView) findViewById(R.id.mListView);
		Button btn_left = (Button) findViewById(R.id.btn_left);
		mXList.setPullRefreshEnable(true);
		mXList.setPullLoadEnable(true);
		mXList.setXListViewListener(this);

		btn_hd = (Button) findViewById(R.id.btn_hd);
		btn_hd.setVisibility(View.VISIBLE);
		btn_hd.setOnClickListener(this);
		btn_ty = (Button) findViewById(R.id.btn_ty);
		btn_ty.setVisibility(View.GONE);
		btn_ty.setOnClickListener(this);
		btn_classification = (Button) findViewById(R.id.btn_classification);
		btn_classification.setVisibility(View.VISIBLE);
		btn_classification.setOnClickListener(this);
		// mListView = (ListView) findViewById(R.id.mListView);
		dataAdapter = new DataAdapter(this);
		mXList.setAdapter(dataAdapter);
		startProgressDialog();
		if (!init) {
			resultList.clear();
			dataAdapter.notifyDataSetChanged();
		}
		pageNo = "0";
		if (!TextUtils.isEmpty(getIntent().getStringExtra("sectionId"))) {

			btn_left.setVisibility(View.VISIBLE);
			btn_left.setOnClickListener(this);
			btn_classification.setVisibility(View.GONE);
			btn_hd.setVisibility(View.GONE);
			btn_ty.setVisibility(View.GONE);
			sectionId = getIntent().getStringExtra("sectionId");

			getClubData();
		} else if (!TextUtils.isEmpty(getIntent().getStringExtra("userId"))) {

			btn_left.setVisibility(View.VISIBLE);
			btn_left.setOnClickListener(this);
			userId = getIntent().getStringExtra("userId");
			btn_classification.setVisibility(View.GONE);
			btn_hd.setVisibility(View.GONE);
			btn_ty.setVisibility(View.GONE);
			getPersonalData();
		} else if (!TextUtils.isEmpty(getIntent().getStringExtra("ThemeId"))) {

			btn_left.setVisibility(View.VISIBLE);
			btn_left.setOnClickListener(this);
			ThemeId = getIntent().getStringExtra("ThemeId");
			btn_classification.setVisibility(View.GONE);
			btn_hd.setVisibility(View.GONE);
			btn_ty.setVisibility(View.GONE);
			getThemeData();
		} else {
			jsonData("");
		}

		init = false;
	}

	protected void resetXList() {

		mXList.setRefreshTime(new SimpleDateFormat("H:mm", Locale.CHINA).format(new Date()));
		mXList.stopRefresh();
		mXList.stopLoadMore();
	}

	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.btn_left:
			finish();
			break;
		case R.id.btn_hd:
			isJoined = true;
			btn_hd.setVisibility(View.GONE);
			btn_ty.setVisibility(View.VISIBLE);
			pageNo = "0";
			flgMore = false;
			startProgressDialog();
			getMyMessageList();
			break;
		case R.id.btn_ty:
			isJoined = false;
			flgMore = false;
			btn_hd.setVisibility(View.VISIBLE);
			btn_ty.setVisibility(View.GONE);
			pageNo = "0";
			startProgressDialog();
			jsonData("");
			break;
		case R.id.btn_classification:
			Intent intent = new Intent();
			intent.setClass(GroupActivity.this, GroupClassificationActivity.class);
			startActivityForResult(intent, 0);
			break;
		default:
			break;
		}

	}

	@SuppressWarnings("unchecked")
	private void jsonData(String bc) {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "queryMessageListNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("pageNo", pageNo));
		params.add(new BasicNameValuePair("bc", bc));
		new HttpPostRequestAsyncTask(GroupActivity.this, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	@Override
	public void onSuccess(Object object) {

		// stopProgressDialog();
		stopProgressDialog();
		Type type = new TypeToken<List<GroupBean>>() {
		}.getType();
		Gson gson = new Gson();
		String result = (String) object;

		try {

			mDataList = gson.fromJson(result, type);
		} catch (Exception e) {
			return;
		}
		if (mDataList != null) {

			if (flgMore) {
				if (mDataList.size() == 0) {
					Toast.makeText(getApplicationContext(), "已经加载全部", Toast.LENGTH_SHORT).show();
					if (!"1".equals(pageNo)) {
						pageNo = String.valueOf(Integer.parseInt(pageNo) - 1);
					} else {
						pageNo = "0";
					}
					resetXList();
				} else {

					resultList.clear();

					for (GroupBean bean : mDataList) {
						resultList.add(bean);
						totalList.add(bean);
					}
					dataAdapter.addItemLast(resultList);
					resetXList();

				}
			} else {
				if (mDataList.size() == 0) {

					Toast.makeText(getApplicationContext(), "已经加载全部", Toast.LENGTH_SHORT).show();
					resultList.clear();
					resetXList();
				}
				resultList.clear();
				totalList.clear();

				for (GroupBean bean : mDataList) {
					resultList.add(bean);
					totalList.add(bean);
				}
				dataAdapter.addItemTop(resultList);
				dataAdapter.notifyDataSetChanged();
				resetXList();
			}

			if (comeFromPush) {
				Intent intent = new Intent();
				intent.setClass(this, GroupDetailActivity.class);
				intent.putExtra("messageId", newMessageId);
				startActivity(intent);
				comeFromPush = false;

			}
		} else {
			Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
		}

	}

	@Override
	public void onFail(String exception) {

		// stopProgressDialog();
		stopProgressDialog();
		dataAdapter = new DataAdapter(GroupActivity.this);
		mXList.setAdapter(dataAdapter);
		Alert.error(GroupActivity.this,"与服务器连接失败，请检查网络");
		resetXList();
	}

	@SuppressWarnings("unchecked")
	private void getClubData() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "queryMessageBySectionNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("sectionId", sectionId));
		params.add(new BasicNameValuePair("pageNo", pageNo));

		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				stopProgressDialog();
				Type type = new TypeToken<List<GroupBean>>() {
				}.getType();
				Gson gson = new Gson();
				String result = (String) object;

				try {

					mDataList = gson.fromJson(result, type);
				} catch (Exception e) {
					return;
				}
				if (mDataList != null) {
					if (flgMore) {
						if (mDataList.size() == 0) {
							Toast.makeText(getApplicationContext(), "目前没有更多活动", Toast.LENGTH_SHORT).show();
							if (!"1".equals(pageNo)) {
								pageNo = String.valueOf(Integer.parseInt(pageNo) - 1);
							} else {
								pageNo = "0";
							}
							resetXList();
						} else {

							resultList.clear();

							for (GroupBean bean : mDataList) {
								resultList.add(bean);
								totalList.add(bean);
							}
							dataAdapter.addItemLast(resultList);
							resetXList();

						}
					} else {
						resultList.clear();
						totalList.clear();
						if (mDataList.size() == 0) {

							Toast.makeText(getApplicationContext(), "已经加载全部", Toast.LENGTH_SHORT).show();

							resetXList();
						}
						for (GroupBean bean : mDataList) {
							resultList.add(bean);
							totalList.add(bean);

						}
						dataAdapter.addItemTop(resultList);
						dataAdapter.notifyDataSetChanged();
						resetXList();
					}
				} else {
					Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
				}

			}

			@Override
			public void onFail(String exception) {

				Alert.error(GroupActivity.this,"与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.USER).execute(params);
	}

	@SuppressWarnings("unchecked")
	private void getMyMessageList() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "queryMyMessageListNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("pageNo", pageNo));

		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				stopProgressDialog();
				Type type = new TypeToken<List<GroupBean>>() {
				}.getType();
				Gson gson = new Gson();
				String result = (String) object;

				try {

					mDataList = gson.fromJson(result, type);
				} catch (Exception e) {
					return;
				}
				if (mDataList != null) {
					if (flgMore) {
						if (mDataList.size() == 0) {
							Toast.makeText(getApplicationContext(), "目前没有更多活动", Toast.LENGTH_SHORT).show();
							if (!"1".equals(pageNo)) {
								pageNo = String.valueOf(Integer.parseInt(pageNo) - 1);
							} else {
								pageNo = "0";
							}
							resetXList();
						} else {

							resultList.clear();

							for (GroupBean bean : mDataList) {
								resultList.add(bean);
							}
							dataAdapter.addItemLast(resultList);
							resetXList();

						}
					} else {
						if (mDataList.size() == 0) {

							Toast.makeText(getApplicationContext(), "已经加载全部", Toast.LENGTH_SHORT).show();
							resultList.clear();
							resetXList();
						}
						resultList.clear();
						for (GroupBean bean : mDataList) {
							resultList.add(bean);

						}
						dataAdapter.addItemTop(resultList);
						dataAdapter.notifyDataSetChanged();
						resetXList();
					}
				} else {
					Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
				}

			}

			@Override
			public void onFail(String exception) {

				Alert.error(GroupActivity.this,"与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	@SuppressWarnings("unchecked")
	private void getPersonalData() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "joinMessageListNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", userId));
		params.add(new BasicNameValuePair("pageNo", pageNo));
		params.add(new BasicNameValuePair("myId", DataStore.getInstance().getUserId()));
		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				stopProgressDialog();
				Type type = new TypeToken<List<GroupBean>>() {
				}.getType();
				Gson gson = new Gson();
				String result = (String) object;

				try {

					mDataList = gson.fromJson(result, type);
				} catch (Exception e) {
					return;
				}
				if (mDataList != null) {
					if (flgMore) {
						if (mDataList.size() == 0) {
							Toast.makeText(getApplicationContext(), "目前没有更多活动", Toast.LENGTH_SHORT).show();
							if (!"1".equals(pageNo)) {
								pageNo = String.valueOf(Integer.parseInt(pageNo) - 1);
							} else {
								pageNo = "0";
							}
							resetXList();
						} else {

							resultList.clear();

							for (GroupBean bean : mDataList) {
								resultList.add(bean);
								totalList.add(bean);
							}
							dataAdapter.addItemLast(resultList);
							resetXList();

						}
					} else {
						totalList.clear();
						if (mDataList.size() == 0) {

							Toast.makeText(getApplicationContext(), "已经加载全部", Toast.LENGTH_SHORT).show();
							resultList.clear();
							resetXList();
						}
						for (GroupBean bean : mDataList) {
							resultList.add(bean);
							totalList.add(bean);

						}
						dataAdapter.addItemTop(resultList);
						resetXList();
					}
				} else {
					Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
				}

			}

			@Override
			public void onFail(String exception) {

				Alert.error(GroupActivity.this,"与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.USER).execute(params);
	}

	@SuppressWarnings("unchecked")
	private void getThemeData() {

		List<NameValuePair> params = new ArrayList<NameValuePair>(); // 使用NameValuePair来保存要传递的Post参数
		params.add(new BasicNameValuePair("cmd", "queryPmMessageListNew1")); // 添加要传递的参数
		params.add(new BasicNameValuePair("userId", DataStore.getInstance().getUserId()));
		params.add(new BasicNameValuePair("pmId", ThemeId));
		params.add(new BasicNameValuePair("pageNo", pageNo));

		new HttpPostRequestAsyncTask(new RequestResultCallback() {

			@Override
			public void onSuccess(Object object) {

				stopProgressDialog();
				Type type = new TypeToken<List<GroupBean>>() {
				}.getType();
				Gson gson = new Gson();
				String result = (String) object;

				try {

					mDataList = gson.fromJson(result, type);
				} catch (Exception e) {
					return;
				}
				if (mDataList != null) {
					if (flgMore) {
						if (mDataList.size() == 0) {
							Toast.makeText(getApplicationContext(), "目前没有更多活动", Toast.LENGTH_SHORT).show();
							if (!"1".equals(pageNo)) {
								pageNo = String.valueOf(Integer.parseInt(pageNo) - 1);
							} else {
								pageNo = "0";
							}
							resetXList();
						} else {

							resultList.clear();

							for (GroupBean bean : mDataList) {
								resultList.add(bean);
								totalList.add(bean);
							}
							dataAdapter.addItemLast(resultList);
							resetXList();

						}
					} else {
						resultList.clear();
						totalList.clear();
						if (mDataList.size() == 0) {

							Toast.makeText(getApplicationContext(), "已经加载全部", Toast.LENGTH_SHORT).show();

							resetXList();
						}
						for (GroupBean bean : mDataList) {
							totalList.add(bean);
							resultList.add(bean);

						}
						dataAdapter.addItemTop(resultList);
						dataAdapter.notifyDataSetChanged();
						resetXList();
					}
				} else {
					Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
				}

			}

			@Override
			public void onFail(String exception) {

				Alert.error(GroupActivity.this,"与服务器连接失败，请检查网络");

			}
		}, GroupBean.class, AppConfig.GROUP).execute(params);
	}

	class DataAdapter extends BaseAdapter {

		private LayoutInflater inflater;
		private ImageLoader imageLoader = null;
		private LinkedList<GroupBean> resultList;

		DataAdapter(Activity activity) {

			inflater = LayoutInflater.from(activity);
			imageLoader = ImageLoader.getInstance();
			resultList = new LinkedList<GroupBean>();
		}

		public void addItemLast(List<GroupBean> datas) {
			resultList.addAll(datas);
		}

		public void addItemTop(List<GroupBean> datas) {
			resultList.clear();
			for (GroupBean info : datas) {
				resultList.add(info);
			}
		}

		@Override
		public int getCount() {

			return resultList.size();
		}

		@Override
		public Object getItem(int arg0) {

			return resultList.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {

			return arg0;
		}

		@Override
		public View getView(final int position, View view, ViewGroup arg2) {
			final ViewHolder viewHolder;
			if (view == null) {
				viewHolder = new ViewHolder();
				view = inflater.inflate(R.layout.group_item, null);
				viewHolder.group_img = (ImageView) view.findViewById(R.id.group_img);
				viewHolder.group_title = (TextView) view.findViewById(R.id.group_title);
				viewHolder.joined_num = (TextView) view.findViewById(R.id.group_joined_num);
				viewHolder.limit_num = (TextView) view.findViewById(R.id.group_limit_num);
				viewHolder.group_time = (TextView) view.findViewById(R.id.group_time);
				viewHolder.feedbackCoin = (TextView) view.findViewById(R.id.feedbackCoin);

				viewHolder.group_description = (TextView) view.findViewById(R.id.group_description);
				viewHolder.berserk = (ImageView) view.findViewById(R.id.berserk);
				viewHolder.invitation = (ImageView) view.findViewById(R.id.invitation);
				viewHolder.group_type = (ImageView) view.findViewById(R.id.group_type);
				viewHolder.make_an_appointment = (TextView) view.findViewById(R.id.make_an_appointment);
				viewHolder.rmb = (TextView) view.findViewById(R.id.rmb);

				view.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolder) view.getTag();
			}

			// 判断添加标签
			if ("1".equals(resultList.get(position).getIsBerserk())) {
				viewHolder.berserk.setVisibility(View.VISIBLE);
			} else {
				viewHolder.berserk.setVisibility(View.GONE);
			}
			if ("0".equals(resultList.get(position).getInvite())) {
				viewHolder.invitation.setVisibility(View.GONE);
			} else if ("1".equals(resultList.get(position).getInvite())) {
				viewHolder.invitation.setVisibility(View.VISIBLE);
			}
			// 抢机会
			if ("0".equals(resultList.get(position).getJoinFlag())) {
				viewHolder.limit_num.setVisibility(View.VISIBLE);
				viewHolder.group_type.setVisibility(View.VISIBLE);
				viewHolder.joined_num.setVisibility(View.VISIBLE);
				viewHolder.make_an_appointment.setVisibility(View.GONE);
				viewHolder.group_type.setImageResource(R.drawable.group_recruit);
				viewHolder.joined_num.setBackgroundResource(R.drawable.group_join_num1);
				viewHolder.joined_num.setTextColor(getResources().getColor(R.color.main_title));
				viewHolder.joined_num.setText(resultList.get(position).getJoinCount());
				// 已抢到
			} else if ("1".equals(resultList.get(position).getJoinFlag())) {
				viewHolder.limit_num.setVisibility(View.VISIBLE);
				viewHolder.group_type.setVisibility(View.VISIBLE);
				viewHolder.joined_num.setVisibility(View.VISIBLE);
				viewHolder.make_an_appointment.setVisibility(View.GONE);
				viewHolder.group_type.setImageResource(R.drawable.group_joined);
				viewHolder.joined_num.setBackgroundResource(R.drawable.group_join_num2);
				viewHolder.joined_num.setTextColor(getResources().getColor(R.color.group_make_an_appointment));
				viewHolder.joined_num.setText(resultList.get(position).getJoinCount());
				// 已参加
			} else if ("2".equals(resultList.get(position).getJoinFlag())) {
				viewHolder.limit_num.setVisibility(View.VISIBLE);
				viewHolder.group_type.setVisibility(View.VISIBLE);
				viewHolder.joined_num.setVisibility(View.VISIBLE);
				viewHolder.make_an_appointment.setVisibility(View.GONE);
				viewHolder.group_type.setImageResource(R.drawable.group_joined);
				viewHolder.joined_num.setBackgroundResource(R.drawable.group_join_num2);
				viewHolder.joined_num.setTextColor(getResources().getColor(R.color.group_make_an_appointment));
				viewHolder.joined_num.setText(resultList.get(position).getJoinCount());
				// 已过期
			} else if ("3".equals(resultList.get(position).getJoinFlag())) {
				viewHolder.limit_num.setVisibility(View.VISIBLE);
				viewHolder.group_type.setVisibility(View.VISIBLE);
				viewHolder.joined_num.setVisibility(View.VISIBLE);
				viewHolder.make_an_appointment.setVisibility(View.GONE);
				viewHolder.group_type.setImageResource(R.drawable.icon_over);
				viewHolder.joined_num.setBackgroundResource(R.drawable.group_join_num4);
				viewHolder.joined_num.setTextColor(getResources().getColor(R.color.group_over));
				viewHolder.joined_num.setText(resultList.get(position).getJoinCount());
				// 报名止
			} else if ("4".equals(resultList.get(position).getJoinFlag())) {
				viewHolder.limit_num.setVisibility(View.VISIBLE);
				viewHolder.group_type.setVisibility(View.VISIBLE);
				viewHolder.joined_num.setVisibility(View.VISIBLE);
				viewHolder.make_an_appointment.setVisibility(View.GONE);
				viewHolder.group_type.setImageResource(R.drawable.group_over);
				viewHolder.joined_num.setBackgroundResource(R.drawable.group_join_num4);
				viewHolder.joined_num.setTextColor(getResources().getColor(R.color.group_over));
				viewHolder.joined_num.setText(resultList.get(position).getJoinCount());
				// 已报满
			} else if ("5".equals(resultList.get(position).getJoinFlag())) {
				viewHolder.limit_num.setVisibility(View.VISIBLE);
				viewHolder.group_type.setVisibility(View.VISIBLE);
				viewHolder.joined_num.setVisibility(View.VISIBLE);
				viewHolder.make_an_appointment.setVisibility(View.GONE);
				viewHolder.group_type.setImageResource(R.drawable.group_full);
				viewHolder.joined_num.setBackgroundResource(R.drawable.group_join_num3);
				viewHolder.joined_num.setTextColor(getResources().getColor(R.color.group_full));
				viewHolder.joined_num.setText(resultList.get(position).getJoinCount());
				// 预约
			} else if ("6".equals(resultList.get(position).getJoinFlag())) {
				viewHolder.limit_num.setVisibility(View.INVISIBLE);
				viewHolder.group_type.setVisibility(View.VISIBLE);
				viewHolder.group_type.setImageResource(R.drawable.group_make_an_appointment);
				viewHolder.joined_num.setVisibility(View.INVISIBLE);
				viewHolder.make_an_appointment.setVisibility(View.VISIBLE);
				// 已预约
			} else if ("7".equals(resultList.get(position).getJoinFlag())) {
				viewHolder.limit_num.setVisibility(View.INVISIBLE);
				viewHolder.group_type.setVisibility(View.VISIBLE);
				viewHolder.group_type.setImageResource(R.drawable.group_make_an_appointment);
				viewHolder.joined_num.setVisibility(View.INVISIBLE);
				viewHolder.make_an_appointment.setVisibility(View.VISIBLE);
			} else {

			}

			Spannable WordtoSpan = new SpannableString("￥" + resultList.get(position).getJoinRmb());
			WordtoSpan.setSpan(new AbsoluteSizeSpan(50), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			viewHolder.rmb.setText(WordtoSpan);
			viewHolder.group_time.setText(resultList.get(position).getTime());

			viewHolder.limit_num.setText("/" + resultList.get(position).getLimitCount());
			// 字体加粗
			TextPaint tp = viewHolder.group_title.getPaint();
			tp.setFakeBoldText(true);
			TextPaint tp2 = viewHolder.feedbackCoin.getPaint();
			tp2.setFakeBoldText(true);
			viewHolder.group_title.setText(resultList.get(position).getTitle());
			viewHolder.feedbackCoin.setText("+" + resultList.get(position).getCoin());
			viewHolder.group_description.setText(resultList.get(position).getSimpleContent());
			// viewHolder.group_description.setText("主办方简介主办方简介主办方简介主办方简介主办方简介主办方简介主办方简介");
			if (!"".equals(resultList.get(position).getLogo())) {
				imageLoader.displayImage(AppConfig.HOST + resultList.get(position).getLogo(), viewHolder.group_img,
						Constants.image_display_options, AppConfig.animateListener);
			} else {
				viewHolder.group_img.setImageResource(R.drawable.ic_stub);
			}

			view.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent();
					intent.setClass(GroupActivity.this, GroupDetailActivity.class);
					intent.putExtra("messageId", resultList.get(position).getMessageId());
					intent.putExtra("position", position);
					GroupActivity.this.startActivityForResult(intent, AppConfig.REQUEST_GROUP);
				}
			});
			return view;
		}

		class ViewHolder {
			TextView group_title, group_time, joined_num, limit_num, limit_text, group_content, feedbackCoin,
					group_description, rmb, make_an_appointment;
			LinearLayout myLayout;
			ImageView group_img, isjoin, activity_img, group_time_img, berserk, invitation, group_type;
			Button group_join, group_discuss;

		}
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (resultCode == RESULT_OK) {
			if (requestCode == AppConfig.REQUEST_GROUP) {
				if (data == null) {
					return;
				}
				int pos = data.getExtras().getInt("position");
				boolean isSigned = data.getExtras().getBoolean("isSigned", false);
				boolean isOrder = data.getExtras().getBoolean("isOrder", false);
				Object object = dataAdapter.getItem(pos);
				if (object instanceof GroupBean) {
					GroupBean groupBean = (GroupBean) object;
					int signedNumber = Integer.parseInt(totalList.get(pos).getJoinCount());
					int orderNumber = Integer.parseInt(totalList.get(pos).getOrderCount());
					if (isSigned) {
						signedNumber = signedNumber + 1;
						groupBean.setJoinCount(signedNumber + "");
						// 没有报名是0，1是报名
						groupBean.setJoinFlag("1");

					}
					if (isOrder) {
						orderNumber = orderNumber + 1;
						groupBean.setJoinCount(orderNumber + "");
						// 没有报名是0，1是报名
						groupBean.setJoinFlag("7");

					}

					dataAdapter.notifyDataSetChanged();
				}
			} else if (requestCode == 0) {
				if (resultCode == RESULT_OK) {
					if (data.getStringExtra("childPosition") != null) {
						bc = data.getStringExtra("childPosition");
						flgMore = false;
						resultList.clear();
						pageNo = "0";
						jsonData(bc);
					}

				}
			}
		}

	}

	@Override
	public void onRefresh() {

		flgMore = false;
		resultList.clear();
		pageNo = "0";
		if (!TextUtils.isEmpty(sectionId)) {
			getClubData();
		} else if (!TextUtils.isEmpty(userId)) {
			getPersonalData();
		} else if (isJoined) {
			getMyMessageList();
		} else if (!TextUtils.isEmpty(getIntent().getStringExtra("ThemeId"))) {

			getThemeData();
		} else {
			jsonData("");
		}

	}

	@Override
	public void onLoadMore() {

		flgMore = true;
		pageNo = String.valueOf(Integer.parseInt(pageNo) + 1);
		if (!TextUtils.isEmpty(sectionId)) {
			getClubData();
		} else if (!TextUtils.isEmpty(userId)) {
			getPersonalData();
		} else if (isJoined) {

			getMyMessageList();
		} else if (!TextUtils.isEmpty(getIntent().getStringExtra("ThemeId"))) {

			getThemeData();
		} else {
			jsonData(bc);
		}

	}

	private void startProgressDialog() {
		if (progressDialog == null) {
			progressDialog = CustomProgressDialog.createDialog(this);
			progressDialog.setMessage("正在加载...");
		}

		progressDialog.show();
	}

	private void stopProgressDialog() {
		if (progressDialog != null) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}

}
